<template>
  <div class="photoinfo-container">
      <h3>{{ photoinfo.title }}</h3>
      <p class="subtitle">
        <span>发表时间：{{ photoinfo.add_time | dateFormat }}</span>
        <span>点击：{{ photoinfo.click }}次</span>
      </p>
        <hr>
        <!-- 缩略图区域 -->
        <div class="thumbs">
            <img class="preview-img" v-for="(item, index) in imgList" :src="item.src" height="100" @click="$preview.open(index, imgList)" :key="item.src">
        </div>

        <!-- 图片内容区域  -->
        <div class="content" v-html="photoinfo.content"></div>

        <!-- 下方评论组件 -->
        <cms-box :id="id"></cms-box>

  </div>
</template>
<script>
import commtent from '../../components/news/subcomponents/comment.vue'



export default {
  data(){
      return {
          id : this.$route.params.id,
          photoinfo:[],
          imgList:[]
      }
  },
  created(){
      this.getPhotoinfo()
      this.getImage()
  },
  methods:{
      getPhotoinfo(){
          this.$http.get('api/getimageInfo/'+this.id).then(result=>{
              if(result.body.status === 0){
                  this.photoinfo = result.body.message[0]
              }
          })
      },
      getImage(){
          this.$http.get('api/getthumimages/'+this.id).then(result=>{
              if(result.body.status === 0){
                  // 循环每个图片数据，补全图片的宽和高
                  result.body.message.forEach(item =>{
                      item.w = 600;
                      item.h = 400;
                  })
                  // 把完整的数据保存到 list 中
                 this.imgList = result.body.message
                 console.log(this.imgList)
              }
          })
      }
  },
  components:{
      'cms-box':commtent
  }
}
</script>
<style lang="less" scoped>
    .photoinfo-container {
        padding: 3px;
        h3 {
            color: #26A2Ff;
            font-size: 15px;
            text-align: center;
            margin: 15px 0;
        }
        .subtitle{
            display: flex;
            justify-content: space-between;
        }
        .content {
            line-height: 30px;
            font-size: 13px;
        }
    }
</style>


